package com.hand.demo.config.handler;

import org.hzero.boot.scheduler.infra.annotation.JobHandler;
import org.hzero.boot.scheduler.infra.enums.ReturnT;
import org.hzero.boot.scheduler.infra.handler.IJobHandler;
import org.hzero.boot.scheduler.infra.tool.SchedulerTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 *
 */
@JobHandler("jobTest")
public class MyJobHandler implements IJobHandler {
    private static final Logger logger = LoggerFactory.getLogger(MyJobHandler.class);

    @Override
    public ReturnT execute(Map<String, String> map, SchedulerTool tool) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.info(e.toString());
        }
        tool.updateProgress(100, "任务进行中。。。");
        tool.info("示例任务1执行成功！" + "租户ID为：" + tool.getBelongTenantId());
        return ReturnT.SUCCESS;
    }

    @Override
    public void onCreate(SchedulerTool tool) {
        tool.info("在执行任务前初始化参数");
    }

    @Override
    public void onException(SchedulerTool tool) {
        tool.info("出错了");
    }

    @Override
    public void onFinish(SchedulerTool tool, ReturnT returnT) {
        tool.info("结束了");
    }
}
